﻿using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace Sample.ConsoleApp.CodeFist.Sqlite.TypeConverters;

/// <summary>
/// DateTime 转换器
/// </summary>
internal class DateTimeToStringConverter : ValueConverter<DateTime, string>
{
    /// <summary>
    /// 日期格式
    /// </summary>
    private static readonly string _timeFormat = "yyyy-MM-dd HH:mm:ss.SSS";

    public DateTimeToStringConverter(ConverterMappingHints? mappingHints = null)
        : base(
            v => v.ToString(_timeFormat),
            v => DateTime.ParseExact(v, _timeFormat, null),
            mappingHints)
    {
    }
}
